Thumb

JavaScript Let keyword

1/22/2020 1:09:49 AM

JavaScript have “let” keyword like “var” keyword. But many deference between var and let keyword. Var keyword accessible to ta global of the scope but other side let keyword only accessible their block. However, one the other hand var keyword attach the window property so programmer can access the variable out of the programming but let keyword only access from the program. Now given bellow the example code and explain the code:

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<script type="text/javascript">
function StartVar(){
//using var keyword
for(var i=0;i<=5;i++){
console.log("Inside Value of i: "+i);
}
console.log("Out side Value of i: "+i);
}
 StartVar();


function StartLet(){
 //using let keyword
for(let i=0;i<=5;i++){
console.log("Inside Value of i: "+i);
}
console.log("Out side Value of i: "+i);
}
StartLet();

</script>
</body>
</html>

In this code we show the var and let keywords how to work. Let keyword work only the inside of the scope and var keyword work out side of the scope. Also, window property attaches the var keyword value but let keyword can’t attach. So let keyword is more secure then var keyword.